export function searchColumns() {
  return [
    {
      prop: 'name',
      placeholder: '请输入人群名称',
    },
  ]
}

export function tableColumns() {
  const formatRule = row => {
    const rul = {
      count: '有效购买次数',
      amount: '有效购买金额',
      day: '近x天无购买',
    }
    const rules = {
      eq: '等于',
      gt: '大于',
      lt: '小于',
    }
    let t_rules = []
    for (let i in row.rule) {
      if (Object.keys(row.rule).includes('day')) {
        for (let j in row.rule[i]) {
          const t_r = `${rul[i]}${rules[j]}${
            i === 'amount' ? row.rule[i][j] / 10000 : row.rule[i][j]
          }`
          t_rules.push(t_r)
        }
        if (typeof row.rule[i] === 'number') {
          const day = `近${row.rule[i]}天无购买`
          t_rules.push(day)
        }
      } else {
        for (let j in row.rule[i]) {
          const t_r = `${rul[i]}${rules[j]}${
            i === 'amount' ? row.rule[i][j] / 10000 : row.rule[i][j]
          }`
          t_rules.push(t_r)
        }
      }
    }
    return t_rules.join(',')
  }
  return [
    {
      label: '人群名称',
      prop: 'name',
    },
    {
      align: 'left',
      label: '人群定义',
      prop: 'rule',
      formatter: row => formatRule(row),
    },
    {
      width: 200,
      label: '人群数量',
      prop: 'count',
    },
  ]
}
